<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        p{
            font-size: 20px;
            color: red;
            font-weight: bold;
            position: fixed;
            top: 0;
            left: 0;
            
        }
    </style>
</head>
<body data-spy="scroll" data-target=".navbar-example">
    <div style="height: 5000px;background-color: yellowgreen;">
    <p class="zi">滑动 </p>
    </div>
</body>
<script> 
    var xyz = document.querySelector('.zi')
        
    window.onscroll = function() {
  //为了保证兼容性，这里取两个值，哪个有值取哪一个
  //scrollTop就是触发滚轮事件时滚轮的高度
  var scrollTop = document.documentElement.scrollTop ;
  console.log("滚动距离" + scrollTop);
 }
        function a(){
            if (scrollTop>400) {
                xyz.style.opicaty = "0";
            }else{
                xyz.style.opicaty = "1";
            }
        }
        a();
</script>
</html>